<!doctype html>
<html>
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>
    <meta charset="UTF-8">
    <title>自定义推送</title>

    {% include 'template/baseCss.volt' %}
    <link href="/css/vendor/manual-push.less" rel="stylesheet/less" type="text/css">
    <script src="/js/less.min.js"></script>
</head>

<body>
<main>
    <div class="mail-content">
        <table class="push-info" cellpadding="0" cellspacing="0">
            <tr>
                <td><h2>推送类型:</h2></td>
                <td class="value">
                    <select id="push-type">
                        <option value="1">自定义</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td><h2>推送方式:</h2></td>
                <td class="value">
                    <input type='checkbox' name='push-style' value='monitor' id='cb-monitor'><label
                            for='cb-monitor'>监控平台</label>
                    <input type='checkbox' name='push-style' value='email' id='cb-email'><label
                            for='cb-email'>邮箱</label>
                    <input type='checkbox' name='push-style' value='msg' id='cb-msg'><label for='cb-msg'>短信</label>
                    <input type='checkbox' name='push-style' value='manager' id='cb-manager'><label
                            for='cb-manager'>管家</label>
                </td>
            </tr>
        </table>

        <h2>接收人:</h2>
        <div id="receiver-box">
            <div id="receiver-list">
                <!-- 已选择的接收人列表 -->
            </div>
            <p class="fold-toggle button remove" onClick="manualPushM.clickReceiverFoldToggle(this)">展开</p>
        </div>

        <h2 class="title">主题:</h2>
        <input class="theme" type="text" id="msg-title">

        <h2 id="content-body-title" class="title">正文:</h2>
        <div id="msg-content" style="font-size: 1.4rem;">

        </div>

        <p class="send-btn button" onClick="sendMsg()">发 送</p>
    </div>

    <div class="mail-contacts">
        <p class="all-btn button" onClick="manualPushM.clickContactsSelectAll()">选择全部</p>
        <p class="all-btn button" onClick="manualPushM.clickContactsCancelAll(this)">取消全部</p>

        <h2>接收人搜索</h2>
        <input id="contacts-search-input" class="search-bar" type="text" placeholder="搜 索">

        <div class="contacts-box">
            <ul id="contacts-list">
                <!-- 联系人列表 -->
            </ul>
        </div>
    </div>
</main>
<div style="display: none">
    <div id="all-user-info">{{ userList }}</div>

</div>
</body>

{% include 'template/baseJs.volt' %}
<script src="/js/vendor/manual-push.js"></script>
<script type="text/javascript" src="/third-part/wang-editor/wangEditor.min.js"></script>
<script>
    // 初始化源接收人数据
    $(function () {
        //初始化编辑器
        PushViewProxy.init();

    });

    var PushViewProxy = {
        editor:false,
        init: function () {
            var E = window.wangEditor;
            this.editor = new E('#msg-content');
            this.editor.create();

            var list = new Array();
            var userList = eval("(" + $("#all-user-info").text() + ")");
            for (var i = 0; i < userList.length; i++) {
                var item = userList[i];
                var title = item["phone"];
                if (item["nickname"]) {
                    title += "(" + item["nickname"] + ")";
                }
                var email = "邮箱:";
                if (item["email"]) {
                    email += item["email"];
                } else {
                    email += "未知";
                }
                var itemView = {
                    title: title,
                    detail: email,
                    id: item["id"],
                    selected: false
                };
                list.push(itemView);
            }
            manualPushM.updateAllContacts(list);

            this.updatePushMethod();
        },
        //更新推送方式
        updatePushMethod: function () {
            var pushType = parseInt($("#push-type").val());
            $("#cb-monitor").attr("disabled", false);
            $("#cb-email").attr("disabled", false);
            $("#cb-manager").attr("disabled", false);
            $("#cb-msg").attr("disabled", false);
            switch (pushType) {
                case 1: {
                    $("#cb-msg").attr("disabled", true);
                }
                    ;
                    break;
            }

        }
    };

    // 点击发送
    function sendMsg() {
        if (DataValidBinder.valid()) {
            var isSelectSendMethod = false;
            var userIdArray = "";
            var params = new Object();
            var title = $("#msg-title").val();
            if (title.length <= 0) {
                FAlert("请输入主题");
                return;
            }
            var content = PushViewProxy.editor.txt.text();
            if (content.length <= 0) {
                FAlert("请输入内容");
                return;
            }

            var receivers = manualPushM.getReceivers();
            for (var i = 0, len = receivers.length; i < len; i++) {

                var item = receivers[i];
                userIdArray += "" + item.id + ",";
            }
            if (userIdArray.length <= 0) {
                FAlert("请选择需要发送的人员");
                return;
            }

            params["user"] = userIdArray;
            params["title"] = title;
            params["content"] = PushViewProxy.editor.txt.text();

            if ($("#cb-monitor").is(':checked')) {
                params["monitor"] = true;
                params["originContent"]=PushViewProxy.editor.txt.html();
                isSelectSendMethod = true;
            }
            if ($("#cb-email").is(':checked')) {
                params["email"] = true;
                isSelectSendMethod = true;
            }

            if ($("#cb-manager").is(':checked')) {
                params["manager"] = true;
                isSelectSendMethod = true;
            }
            if ($("#cb-msg").is(':checked')) {
                params["msg"] = true;
                isSelectSendMethod = true;
            }

            if (!isSelectSendMethod) {
                FAlert("请选择要推送方式");
            } else {
                feimaPost("/notification/doSendMessage", params, function (result) {
                    FAlert(result.message);
                });
            }


        }


    }

</script>

</html>






